<template>
	<uni-search-bar @confirm="toSearch" placeholder="请输入搜索的公交地铁线路" v-model="searchKey" />
	<swiper style="height: 200px;" :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000">
		<swiper-item v-for="(item,index) in lunboList" :key="index">
			<view class="swiper-item">
				<image style="width: 100%;":src="item.url" mode=""></image>
			</view>
		</swiper-item>
	</swiper>
	<view   class="weather" style="height: 100rpx;border: 1px solid #ccc;margin: 5px; border-radius: 5px;display: flex;justify-content: space-between; padding: 10rpx;align-items: center;
				">
				<view class="icon" style="width: 100rpx;height: 100rpx; ">
					<image style="width: 100%;height: 100%;" :src="'/static/color-256/'+ weatherNow.icon +'.png'"
						mode=""></image>
				</view>
				<view class="text" style="font-size: 50rpx;margin-left: 10px;">
					{{weatherNow.temp}}°C
				</view>
				<view class="text" style="font-size: 34rpx;margin-left: 10rpx;">
					{{weatherNow.text}}
				</view>
				<view class="text" style=" margin-left: 10rpx;">
					{{weatherNow.windDir}} {{weatherNow.windScale}}级
				</view>
				<view>
					<view class="text" style="margin-left: 10rpx;">
						体感温度： {{weatherNow.feelsLike }}°C
					</view>
					<view class="text" style="margin-left: 10rpx;">
						湿度： {{weatherNow.humidity }}%
					</view>
				</view>
			</view>
	
</template>

<script setup>
   import {onLoad} from "@dcloudio/uni-app"
   import {ref} from 'vue'
   import { CONFIG } from "../../utils/config"
   import { userStore } from "../../store/userStore.js"

   
   let weatherNow = ref({})
   async function getWeather(){
	   let res = await uni.$get(CONFIG.hefeng_locations,weatherNow.value)
	   console.log(res)
	   if(res.statusCode == 200){
		   weatherNow.value = res.data.now
		   console.log(res.data.now)
	   }
   }

   
   const store=userStore()
   
   const searchKey = ref("")
   

   
   function toSearch(){
	   if(searchKey.value==""){
		   uni.showToast({
		   	title:"请输入查询的公交地图线路",
			icon:"none"
		   })
	   }else{
		    window.location.href =
		       `https://uri.amap.com/line?name=${searchKey.value}&city=029&callnative=0`
	   }
   }
   
   onLoad(()=>{
	   getLunbo()
	   getCurrentPos()
	   getWeather()
   })
   
   
   const lunboList = ref([])
  async function getLunbo(){
	let res= await uni.$get(CONFIG.leanCloud_url+"/1.1/classes/Lunbo")
	if(res.statusCode==200){
		lunboList.value=res.data.results
	}
	console.log(lunboList.value)
   }
   
   function getCurrentPos(){
	uni.getLocation({
		success:function(res){
			console.log('当前位置的经度：'+res.longitude);
			console.log('当前位置的维度：'+res.latitude);
			store.setPos(res.longitude,res.latitude)
		}
	})
   }
</script>

<style lang="scss" scoped>
	
</style>
